package com.ywh.composetest.widget

import android.util.Log
import android.view.View
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.viewinterop.AndroidView

/**
 * 使用AndroidView加载原生的xml/View
 */
@Composable
fun LoadAndroidView(width: Dp, height: Dp) {
    Row {
        var tempView: RectLineCountdownView? = null

        BoxTextCompose(content = "AndroidView:\n原生View/xml转Composable") {
            tempView?.start()
        }

        AndroidView(
            modifier = Modifier
                .size(width, height),
            factory = {
                val view = RectLineCountdownView(it, null)
                tempView = view
                view.setOnClickListener {
                    view.start {
                        Log.e("AndroidView2", ":${it}")
                    }
                }
                view
            }
        ) {
            it.start {
                Log.e("AndroidView", ":${it}")
            }
        }
    }
}